package com.xmy.study.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.study.entity.EduTask;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import scala.Int;

@Mapper
public interface EduTaskMapper extends BaseMapper<EduTask> {

    @Select("select * from edu_task where task_date BETWEEN #{startDate} and #{endDate} and year_class_id = ${yearClassId} and class_type_id =${classTypeId} and course_version_id= ${courseVersionId} and subjects_id=${subjectsId} and task_category_id = ${categoryId}  and deleted = 0 limit 1")
    public EduTask getTaskOneForDate(@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("yearClassId") String yearClassId,@Param("classTypeId") Long classTypeId,@Param("courseVersionId") Long courseVersionId,@Param("subjectsId") Long subjectsId,@Param("categoryId") Integer categoryId);

    @Select("select IFNULL(max(task_course_num),0) as max_num from edu_task where year_class_id = ${yearClassId} and class_type_id =${classTypeId} and course_version_id= ${courseVersionId} and subjects_id=${subjectsId} and task_category_id = ${categoryId} and deleted = 0")
    public Integer getTaskNumForMax(@Param("yearClassId") String yearClassId,@Param("classTypeId") Long classTypeId,@Param("courseVersionId") Long courseVersionId,@Param("subjectsId") Long subjectsId,@Param("categoryId") Integer categoryId);


    @Select("select * from edu_task where task_course_num = ${taskCourseNum} and year_class_id = ${yearClassId} and class_type_id =${classTypeId} and course_version_id= ${courseVersionId} and subjects_id=${subjectsId} and deleted = 0 and year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id = ${categoryId} limit 1")
    public EduTask getTaskOneForTaskCourseNum(@Param("taskCourseNum") Integer taskCourseNum ,@Param("yearClassId") Integer yearClassId,@Param("classTypeId") Long classTypeId,@Param("courseVersionId") Long courseVersionId,@Param("subjectsId") Long subjectsId,@Param("yearPart")Integer yearPart,@Param("quarterNum") Integer quarterNum ,@Param("categoryId") Integer categoryId);


    @Select("select * from edu_task where year_part = ${yearPart} and quarter_num = ${quarterNum} and  ((start_task_date BETWEEN #{startDate} and #{endDate}) or (task_date BETWEEN #{startDate} and #{endDate})) and course_version_id= ${courseVersionId} and subjects_id IN (${subjectsId}) and task_category_id = ${categoryId} and deleted = 0 order by task_course_num desc limit 1")
    public EduTask getTaskOneNow(@Param("yearPart") String yearPart,@Param("quarterNum") String quarterNum,@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("courseVersionId") Long courseVersionId,@Param("subjectsId") String subjectsId,@Param("categoryId") Integer categoryId);


    @Select("select `id`, `year_part`, `quarter_num`, `year_class_id`, `subjects_id`, `class_type_id`, `course_version_id`, `start_task_date`, `task_date`, MAX(`task_course_num`) as `task_course_num`, `lowest_shutnum`, `break_shutnum`, `deleted`, `created_at`, `updated_at` from edu_task where year_part = ${yearPart} and quarter_num = ${quarterNum} and course_version_id= ${courseVersionId} and subjects_id IN (${subjectsId}) and task_category_id = ${categoryId} and deleted = 0 limit 1")
    public EduTask getTaskOneBackTaskNum(@Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("courseVersionId") Long courseVersionId, @Param("subjectsId") String subjectsId,@Param("categoryId") Integer categoryId);

    @Select("select MAX(brush_count) as brush_count from cha_plan where year_part = ${yearPart} and quarter_num = ${quarterNum} and task_category_id = ${categoryId} limit 1")
    public Integer brushCount(@Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum,@Param("categoryId") Integer categoryId);

}
